package org.cx.oa.web.struts.actions;

import java.util.ArrayList;
import java.util.List;

import org.cx.oa.entity.Employee;
import org.cx.oa.entity.RightGroups;
import org.cx.oa.entity.Righte;
import org.cx.oa.util.HibernateSessionUtil;
import org.hibernate.Query;
import org.hibernate.Session;

public class RighteAtion {
	public void getAll(RightGroups rightGroups)
	{
		String  rights=rightGroups.getRights();
		String[] rigs=rights.split(",");
		List<Righte> rightes=new ArrayList<Righte>();
		Session session = HibernateSessionUtil.openSession();
		for (int i = 0; i < rigs.length; i++) {
			Righte righte=(Righte)session.get(Righte.class, Integer.parseInt(rigs[i]));
			if (righte.getSuperior()==null||righte.getSuperior().equals("")) {
				Query q = session.createQuery("from Righte rig  where  rig.superior =" +righte.getRightId());
				List<Righte> rightes2=q.list();
				righte.setRightes(rightes2);
			}
			rightes.add(righte);
		}
		HibernateSessionUtil.CloseSessionAndIfNull();
		rightGroups.setRightes(rightes);
	}
}
